# -*- coding: utf-8 -*-
from db.mysql import MysqlClient
from common.helper import Helper
from common.config import *



class Arrangement(object):

    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "航空意外险"
    # 生成产品数据
    def genProductInfo(self):
        # 保额
        airplane_deaths = ["200000","400000","600000","800000","100000","1600000","2000000"]
        prices = ["5","10","15","20","25","40","50"]
        # 计数变量
        num = 0
        for v in airplane_deaths:

            data = {
                "name":self.name,
                "company":"锦泰保险",
                "days":"1y",
                "people_count":"1",
                "price": Helper.decimalParse(prices[num]),
                "airplane_death":airplane_deaths[num]

            }
            num += 1

            self.mergeTable( data )

    # 合并表格
    def mergeTable(self, data):
        SQL = 'INSERT INTO `' + TABLE_ACCIDENT + '`(`name`,`company`,`days`,`people_count`,`price`,`airplane_death`)VALUES("{name}","{company}","{days}","{people_count}","{price}","{airplane_death}")'

        print(SQL.format(**data))

        self.mysql.cursor.execute(SQL.format(**data))
        self.mysql._conn.commit()


if __name__ == '__main__':

    a = Arrangement()
    a.genProductInfo()